import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/topic/:id/:tab',  //详情
    name: 'Topics',
    component: () => import( '../views/Topic.vue')
  },
  {
    path: '/topic/:id',  //详情
    name: 'Topic',
    component: () => import( '../views/Topic.vue')
  },
  {
    path: '/user/:username',  //个人主页
    name: 'User',
    component: () => import( '../views/User.vue')
  },
  {
    path: '/signin',  //注册
    name: 'Signin',
    component: () => import( '../views/Login.vue')
  },
  {
    path: '/register',  //登录
    name: 'Register',
    component: () => import( '../views/Register.vue')
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to,from,next) => {
//   if (to.path != '/signin') {
//     if (localStorage.getItem('authorization')) {
//       next();
//     } else {
//       next('/signin');
//     }
//   } else {
//     next();
//   }
// })

export default router
